package Z.dailyExercise.holiday;

public class _852_山脉数组的峰顶索引 {
    /**
     * 寻找比左右两边数都小的数值
     *
     * 如果比比右边数小 要往右区间找
     * 如果比左边数小 往左区间找
     * @param arr
     * @return
     */
    public int peakIndexInMountainArray(int[] arr) {
        return helper(arr,0,arr.length-1);



    }

    public int helper(int[] arr,int low,int high){
        if (low>high){
            return -1;
        }
        int mid = low+(high-low)/2;

        if (arr[mid+1] > arr[mid]){
            return helper(arr,mid+1,high);
        }else if (arr[mid-1]>arr[mid]){
            return helper(arr,low,mid-1);
        }else {
            return mid;
        }
    }
}
